package com.ddd.test.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ddd.test.dto.cmd.OrderDTO;
import com.ddd.test.dto.query.SalesOrdersDTO;
import com.ddd.test.query.SalesOrdersQuery;
import com.ddd.test.result.Result;

@Service
public class OrderServiceImpl implements OrderService{
	  @Autowired
	  SalesOrdersQuery salesOrdersQuery;
	
	/**
	   * 聚合查询
	   *
	   * @return Result<SalesOrdersDTO>
	   */
	  public Result<SalesOrdersDTO> queryOrdersBySalesCode( String salescode){
		  Result<SalesOrdersDTO> result = new Result<SalesOrdersDTO>(true);
		  SalesOrdersDTO salesOrdersDTO = salesOrdersQuery.queryOrdersBySalesCode(salescode);
		  List<OrderDTO> orderDTOList = salesOrdersDTO.getOrders();
		  for(OrderDTO orderDTO:orderDTOList) {
			  orderDTO.setAmount(orderDTO.getPrice().multiply(new BigDecimal(orderDTO.getCount())));
		  }
		  result.setObj(salesOrdersDTO);
		  return result;
		  
	  }
	  
	  public Result<String> queryOrdersBySalesCode1( String salescode){
		  Result<String> result = new Result<String>(true);
		  String s = salesOrdersQuery.queryOrdersBySalesCode1(salescode);
		  result.setObj(s);
		  return result;
		  
	  }
}
